#include "login.h"

/**
 * preparo l'interfaccia per il login
 * @param mobj
 */
void login_build_login_interface(main_obj *mobj)
{
    label *l = gui_label_new_label(mobj, "Login");
    gui_util_set_element_pos_flag(mobj, GRAPHIC_ELEMENT(l), GUI_POS_CENTER_H);
    gui_util_set_element_pos(GRAPHIC_ELEMENT(l), GRAPHIC_ELEMENT(l)->posx, LOGIN_START_INTERFACE_Y);
    
    /* etichetta username */
    label *l_username = gui_label_new_label(mobj, "Username:");
    gui_util_set_element_pos(
            GRAPHIC_ELEMENT(l_username),
            gui_util_get_center_x(mobj) - (GUI_BASE_MIN_SPACE + GRAPHIC_ELEMENT(l_username)->graphic->w),
            GRAPHIC_ELEMENT(l)->posy + GRAPHIC_ELEMENT(l)->graphic->h + GUI_BASE_MIN_SPACE
    );
    
    /* textbox username */
    textbox *t_username = gui_textbox_new_empty(mobj);
    gui_util_set_element_pos(
            GRAPHIC_ELEMENT(t_username),
            gui_util_get_center_x(mobj) + GUI_BASE_MIN_SPACE,
            GRAPHIC_ELEMENT(l_username)->posy + ((GRAPHIC_ELEMENT(l_username)->graphic->h - GRAPHIC_ELEMENT(t_username)->graphic->h) / 2)
    );
    
    /*etichetta passsword */
    label *l_password = gui_label_new_label(mobj, "Password:");
    gui_util_set_element_pos(
            GRAPHIC_ELEMENT(l_password),
            gui_util_get_center_x(mobj) - (GUI_BASE_MIN_SPACE + GRAPHIC_ELEMENT(l_password)->graphic->w),
            util_max(GRAPHIC_ELEMENT(l_username)->posy + GRAPHIC_ELEMENT(l_username)->graphic->h, GRAPHIC_ELEMENT(t_username)->posy + GRAPHIC_ELEMENT(t_username)->graphic->h) + GUI_BASE_MIN_SPACE
    );
    /* textbox password */
    textbox *t_password = gui_textbox_new_empty(mobj);
    gui_textbox_set_mode(t_password, GUI_TEXTBOX_MODE_PASSWORD);
    gui_util_set_element_pos(
            GRAPHIC_ELEMENT(t_password),
            gui_util_get_center_x(mobj) + GUI_BASE_MIN_SPACE,
            util_max(GRAPHIC_ELEMENT(l_username)->posy + GRAPHIC_ELEMENT(l_username)->graphic->h, GRAPHIC_ELEMENT(t_username)->posy + GRAPHIC_ELEMENT(t_username)->graphic->h) + GUI_BASE_MIN_SPACE
    );
    /* button di login */
    button *b_login = gui_button_new(mobj, "Login");
    gui_util_set_element_pos_flag(mobj, GRAPHIC_ELEMENT(b_login), GUI_POS_CENTER_H);
    gui_util_set_element_pos(
            GRAPHIC_ELEMENT(b_login),
            GRAPHIC_ELEMENT(b_login)->posx,
            GRAPHIC_ELEMENT(l_password)->posy + GRAPHIC_ELEMENT(l_password)->graphic->h + GUI_BASE_MIN_SPACE
    );
    b_login->click = login_button_click;
    
    /* aggiungo gli elementi pronti all'interfaccia */
    gui_add_element(mobj, GPOINTER(l));
    gui_add_element(mobj, GPOINTER(l_username));
    gui_add_element(mobj, GPOINTER(t_username));
    gui_add_element(mobj, GPOINTER(l_password));
    gui_add_element(mobj, GPOINTER(t_password));
    gui_add_element(mobj, GPOINTER(b_login));
    
}

/**
 * eseguito al click login
 * @param mobj
 * @param b
 * @return 
 */
gboolean login_button_click(main_obj *mobj, button *b)
{
}